/*******************************************************************************
 * This file is part of blueprint4j www.blueprint4j.org.
 * 
 *     blueprint4j is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     blueprint4j is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with blueprint4j. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package blueprint4j.db;

import javax.swing.JProgressBar;

/**
 * Field progress represents a progress bar that scales between - and 100 
 */
public class FieldProgress extends FieldInteger {
	private JProgressBar progress_bar = null;

	public FieldProgress(String name,int field_type,String description,Entity entity) {
		super(name,field_type,description,entity);
	}

	public Field newInstance(Entity entity) {
		return new FieldProgress(getName(),getFieldType(),getDescription(),entity);
	}

	public JProgressBar createProgressBar() {
		progress_bar = new JProgressBar();
		progress_bar.setMaximum(100);
		progress_bar.setMinimum(0);
		if (get() != null ) {
			progress_bar.setValue(get().intValue());
		}
		return progress_bar;
	}

	public void setObject(Object value) {
		super.setObject(value);
		if (progress_bar!= null) {
			if (value != null) {
				progress_bar.setValue(((Integer)value).intValue());
			}else {
				progress_bar.setValue(0);
			}
		}
	}

}
